Chr*_*sic 4 c# asp.net forms-authentication .net-4.0
使用表单身份验证,当应用程序需要重定向到登录页面时,是否有一个事件或任何可扩展点,可以让我在重定向到登录页面之前对请求执行其他工作?
我想在查询字符串中发送可能不同的其他信息,以便在web.config中的loginUrl节点的链接中静态嵌入它.
编辑:为了澄清,我想在重定向到登录页面之前拦截请求.
例:
<authentication mode="Forms">
<forms loginUrl="http://the/interwebs/login.aspx" timeout="2880"
enableCrossAppRedirects="true" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
在用户被重定向到http://the/interwebs/login.aspx之前,我希望能够打包查询值,这样网址可能会像http://the/interwebs/login.aspx一样? =刷新
您可以通过处理事件HttpApplication.AuthenticateRequest来完成此操作
private void Application_AuthenticateRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
if (authCookie == null || string.IsNullOrEmpty(authCookie.Value))
{
//... do something
}
Run Code Online (Sandbox Code Playgroud)
仅供参考,我们目前通过IHttpModule实现这样做.