1.先修改你的web.config:
<authentication mode="Windows"/>
-->>>
<authentication mode="Forms"/>
<authentication mode="Windows"/>
-->>>
<authentication mode="Forms"/>
解决方案 »
- B/S结构的项目中,要求用户账号绑定客户机,除了用ActiveX控件外,有什么其他的好办法吗?
- 查询用的数据集 窗体闪
- Attribute如何同时应用在多个对象上
- 【悬赏100分】listView随机分组问题 快来帮忙啊,弄一天了还没个头绪
- 请问怎样在另一个form中加入processbar,来演示前一个form的运行情况?
- c#[图形应用] GetHbitmap性能问题 Gdi 高手进!!!!
- 一个新手问题,关于连接MSSQL数据库的问题。
- 高手进来一下,如何通过对象的Name属性来获取对象或某一对象的属性
- 如何获取本机名?
- 如何实现声音的时时通讯
- 求救,安装的奇怪的问题
- 动态使用CheckBox时,如何精确控制该WebForms呢?
(FormsIdentity)application.Context.User.Identity;
还有,我不知道你的登录页面如何写的
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 37: HttpResponse response = application.Context.Response;
行 38:
行 39: WindowsIdentity identity =
行 40: (WindowsIdentity)application.Context.User.Identity;
行 41:
源文件: c:\inetpub\wwwroot\ifilter\userlogmodule.cs 行: 39 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
UserLogModule.OnAuthentication(Object sender, EventArgs a) in c:\inetpub\wwwroot\ifilter\userlogmodule.cs:39
System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
<authorization -->>授权
<authentication mode="Windows"/>
改为
<authentication mode="Forms"/>
<authentication mode="Windows"/>
-->>>
<authentication mode="Forms"/>
哎?~~~~~~~~~
我有空,我来回答好了~
这是因为你并没有将用户登陆信息注册进cookies中去~~application.Context.User其实是自动将信息从cookies中提取出来再初始化Principal的~
这个地方确实很多人不理解~但是,不管它,这是ASP.NET自动处理的正确的方法是在用户登陆时执行一个步骤
事先声明,这个步骤可以用SaveAuthCookie() GetAutoCookie() RedirecrFromLoginName()等多种方式解决,最主要的一点就是一定要将特定信息存到Cookie中去
简单验证的方法1
if (验证通过)
System.Security.FormsAuthentication.SetAutoCookie(UserName,false);方法2
if (验证通过)
HttpCookie authenticationCookie=FormsAuthentication.GetAutoCookie(UserName,false);
Response.Cookies.Add(authenticationCookie);复杂的方法比如需要保存自定义的用户信息,需要自定义实现IPrincipal和IIdentity
然后判断Context.User的类型是否为你定义的类型
如果不是,就利用User.Name保存的用户唯一标示来初始化建立你自己的类型的Principal和Identity类,然后
Context.User=yourPrincipal;
一切OK了~~如果还有问题,请去书店购买asp.net安全性高级编程