English 中文(简体)
三. 抽象控制人提出的询问
原标题:request querystring from abstract controller

I want all my pages to use have some viewdata. i need to get a client name from a querystring then based on that do some work and populate ViewData. my controller inherits from the controller created below. Request["client"] is giving System.NullReferenceException: Object reference not set to an instance of an object.

 public abstract class ApplicationController : Controller
    {

        public ApplicationController()
        {
            string client = Request["client"];
            //...etc

        }

    }

这是错误的?

感谢

最佳回答

错过的是,当你在建筑商中称呼该请求时,该请求就不存在,只有在根据你的方法采取行动时才会立即提出。

见这一问题,并探讨答案。 或许对你们也是有用的

如果是使用主计长的话。 HttpContext

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签