Private Function CreateAuthTicket(ByVal userName As String, ByVal roles As String, _
ByVal persistent As Boolean) As FormsAuthenticationTicket
Return New FormsAuthenticationTicket(1, userName, DateTime.Now, _
DateTime.Now.AddMinutes(60), persistent, roles)
End Function
Private Function CreateAuthCookie(ByVal authTicket As FormsAuthenticationTicket) As HttpCookie
Return New HttpCookie(FormsAuthentication.FormsCookieName, _
FormsAuthentication.Encrypt(authTicket))
End Function写在你验证的地方
Dim authTicket As FormsAuthenticationTicket
Dim authCookie As HttpCookie IF 有这个用户意见THENauthTicket = CreateAuthTicket(txtUserID.Text, CStr(viewstate("roles")), False)
authCookie = CreateAuthCookie(authTicket)
HttpContext.Current.Response.Cookies.Add(authCookie)
END IF在web.config 里面增加了下面的代码. 而且也在数据库里面建立了用户表. 但是无论我用什么用户名去登陆, 都不能登陆, 请问我应该用什么用户名去登陆呢? <authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="login.aspx"
protection="All" path="/" timeout="1" />
</authentication> <authorization>
<allow users="*" /> <!-- 允许所有用户 -->
<!-- <allow users="[逗号分隔的用户列表]"
roles="[逗号分隔的角色列表]"/>
<deny users="[逗号分隔的用户列表]"
roles="[逗号分隔的角色列表]"/>
-->
</authorization>
ByVal persistent As Boolean) As FormsAuthenticationTicket
Return New FormsAuthenticationTicket(1, userName, DateTime.Now, _
DateTime.Now.AddMinutes(60), persistent, roles)
End Function
Private Function CreateAuthCookie(ByVal authTicket As FormsAuthenticationTicket) As HttpCookie
Return New HttpCookie(FormsAuthentication.FormsCookieName, _
FormsAuthentication.Encrypt(authTicket))
End Function写在你验证的地方
Dim authTicket As FormsAuthenticationTicket
Dim authCookie As HttpCookie IF 有这个用户意见THENauthTicket = CreateAuthTicket(txtUserID.Text, CStr(viewstate("roles")), False)
authCookie = CreateAuthCookie(authTicket)
HttpContext.Current.Response.Cookies.Add(authCookie)
END IF在web.config 里面增加了下面的代码. 而且也在数据库里面建立了用户表. 但是无论我用什么用户名去登陆, 都不能登陆, 请问我应该用什么用户名去登陆呢? <authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="login.aspx"
protection="All" path="/" timeout="1" />
</authentication> <authorization>
<allow users="*" /> <!-- 允许所有用户 -->
<!-- <allow users="[逗号分隔的用户列表]"
roles="[逗号分隔的角色列表]"/>
<deny users="[逗号分隔的用户列表]"
roles="[逗号分隔的角色列表]"/>
-->
</authorization>
解决方案 »
- asp.net客户端如何用调用标准的win32 dll
- Web.Config的httpHandlers配置
- 这个语句如何理解?
- 怪问题!!SetAuthCookie未能修改Context.User.Identity.Name
- 求助
- 用下面的代码从datagrid导出给客户端下载,在系统弹出的保存对话框里按取消,窗口也随之关闭,为什么?
- 有这么一个语句“Search searchform = (Search)Context.Handler;”我实在不明白。
- ActiveReport:在IIS里面设置的“.ArCacheItem”、“.ActiveReport”、“.rpx”对应的文件路径是什么?
- asp.net中,有什么可以自动扫描网站注入的工具???
- asp图片上传
- 如何编译WebForm1.aspx.cs文件?
- 遇到困难(急求救!!!) 散50分
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="login.aspx"
protection="All" path="/" timeout="1" />
</authentication> <authorization>
<allow users="*" /> <!-- 允许所有用户 -->
<!-- <allow users="[逗号分隔的用户列表]"
roles="[逗号分隔的角色列表]"/>
<deny users="[逗号分隔的用户列表]"
roles="[逗号分隔的角色列表]"/>
-->
</authorization>
然后在你要登陆的页面中加两个FunctionPrivate Function CreateAuthTicket(ByVal userName As String, ByVal roles As String, _
ByVal persistent As Boolean) As FormsAuthenticationTicket
Return New FormsAuthenticationTicket(1, userName, DateTime.Now, _
DateTime.Now.AddMinutes(60), persistent, roles)
End Function
Private Function CreateAuthCookie(ByVal authTicket As FormsAuthenticationTicket) As HttpCookie
Return New HttpCookie(FormsAuthentication.FormsCookieName, _
FormsAuthentication.Encrypt(authTicket))
End Function
如果你点击登陆按钮,你就会到数据库中寻找这个用户和密码,如果存在就写Dim authTicket As FormsAuthenticationTicket
Dim authCookie As HttpCookie authTicket = CreateAuthTicket(txtUserID.Text, CStr(viewstate("roles")), False)
authCookie = CreateAuthCookie(authTicket)
HttpContext.Current.Response.Cookies.Add(authCookie)不存在就EXIT SUB