asp.net mvc when should i read servervariables?

佐手、 提交于 2019-12-02 07:22:26

问题


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");

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..


回答1:


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

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

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



来源:https://stackoverflow.com/questions/975276/asp-net-mvc-when-should-i-read-servervariables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!