Is there a way to process an MVC view (aspx file) from a non-web application?

后端 未结 5 1292
执念已碎
执念已碎 2020-12-14 23:55

I have a background service running which sends out emails to users of my website. I would like to write the email templates as MVC views, to keep things consistent (so tha

5条回答
  •  臣服心动
    2020-12-15 00:46

    This was my first attempt, and it failed. See above for the correct and working answer

    This is as close as I was able to get, but it still didn't work. Now it complains about get_Server causing a NullreferenceException.

    Just thought I'd post on here what I did and how far I got, in case anyone wants to continue the research.

    I modified my csproj file to generate an assembly with the precompiled ASPX files, as such:

    
    ...
        true
        C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\aspnet_merge.exe
    ...
    
    
        
        
        
    
    

    This created a "MyProject_CompiledAspx.dll", which I then referenced from my application. This, however, caused a new NullReferenceException.

    It's a pitty that ASPX files, being as powerful as they are, are so tightly integrated with the ASP.NET server.

提交回复
热议问题