asp.net的MVC时应我读servervariables? [英] asp.net mvc when should i read servervariables?

查看:150
本文介绍了asp.net的MVC时应我读servervariables?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当是apropriate时间(code的一部分),我可以从servervariables收集信息?我的意思是,我试图调用此

When is the apropriate time (part of code) that i can gather information from servervariables? I mean, i have tried calling this

string temp = Request.ServerVariables.Get("HTTP_REMOTE_USER");

在控制器的构造函数,但我得到一个NullPointerException异常,而在一个动作能够正常工作。它只是似乎并不很干净调用它的每个动作。

in the Controller constructor, but i am getting a nullpointerexception, while in an action it works properly. And it just doesnt seem very clean to call it in each action..

推荐答案

您可以在您的控制器或基本控制器定义属性:

You could define a property in your controller or Base Controller:

protected string HttpRemoteUser
{
    get
    {
        return Request.ServerVariables.Get("HTTP_REMOTE_USER");
    }
}

然后调用这个属性在你的行动,而不是Request.ServerVariables.Get

And then call this property in your actions instead of Request.ServerVariables.Get

这篇关于asp.net的MVC时应我读servervariables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆