小编mgn*_*nan的帖子

如何从MVC控制器提供要下载的文件?

在WebForms中,我通常会有这样的代码让浏览器显示一个"下载文件"弹出窗口,其中包含任意文件类型,如PDF和文件名:

Response.Clear()
Response.ClearHeaders()
''# Send the file to the output stream
Response.Buffer = True

Response.AddHeader("Content-Length", pdfData.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment; filename= " & Server.HtmlEncode(filename))

''# Set the output stream to the correct content type (PDF).
Response.ContentType = "application/pdf"

''# Output the file
Response.BinaryWrite(pdfData)

''# Flushing the Response to display the serialized data
''# to the client browser.
Response.Flush()
Response.End()
Run Code Online (Sandbox Code Playgroud)

如何在ASP.NET MVC中完成相同的任务?

asp.net-mvc download

108
推荐指数
3
解决办法
10万
查看次数

无法在Windows Azure上使用RavenDB Embedded写入日志文件

我在Windows Azure上运行MVC网站并使用嵌入式RavenDB.如果网站是"冷"(从Azure实例卸载),我在第一次访问网站时收到以下错误消息:

'/'应用程序中的服务器错误.

写入日志文件失败

描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

异常详细信息:Microsoft.Isam.Esent.Interop.EsentLogWriteFailException:写入日志文件失败

来源错误:

在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.

堆栈跟踪:

[EsentLogWriteFailException:写入日志文件时失败]
Microsoft.Isam.Esent.Interop.Api.Check(Int32错误)+21
Microsoft.Isam.Esent.Interop.Api.JetInit(JET_INSTANCE&instance)+23
Raven.Storage.Esent.TransactionalStorage .Initialize(IUuidGenerator uuidGenerator,OrderedPartCollection`1 documentCodecs)+309

[InvalidOperationException:无法打开事务存储:C:\ DWASFiles\Sites\reflix\VirtualDirectory0\site\wwwroot\App_Data\Data] Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator,OrderedPartCollection`1 documentCodecs)+443
Raven. Database.DocumentDatabase..ctor(InMemoryRavenConfiguration配置)+994
Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal()+313 Raven.Client.Document.DocumentStore.Initialize()+463 Reflix.MvcApplication.InitializeRavenDB(String dataDirectory,Boolean rethrowException) +135 Reflix.MvcApplication.Application_Start()+ 131

[HttpException(0x80004005):无法打开事务存储:C:\ DWASFiles\Sites\reflix\VirtualDirectory0\site\wwwroot\App_Data\Data] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context,HttpApplication app)+9859441
System.Web .HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo [] handlers)+118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state,MethodInfo [] handlers,IntPtr appContext,HttpContext context)+172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance( IntPtr appContext,HttpContext context)+336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)+296

[HttpException(0x80004005):无法打开事务存储:C:\ DWASFiles\Sites\reflix\VirtualDirectory0\site\wwwroot\App_Data\Data] System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+9873784 System.Web.HttpRuntime. EnsureFirstRequestInit(HttpContext context)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)+254

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.18033

如果我等一两分钟,网站就会好起来的.很明显,这是一个首要问题.任何人有任何想法如何解决问题?

我的配置:

  • MVC 4
  • .NET 4.5
  • RavenDB 2.0.2360

更新: Azure团队将此视为Azure网站可能存在的缺陷.我听到更多内容后会立即更新.

azure ravendb asp.net-mvc-4 azure-web-sites

6
推荐指数
1
解决办法
433
查看次数

在asp.net中序列化会话状态

我正在尝试在我们的nopcommerce 1.9安装中将会话状态存储在SQL而不是InProc中.当我对web.config进行必要的更改时,我收到此错误:

'/'应用程序中的服务器错误.

无法序列化会话状态.在"StateServer"和"SQLServer"模式下,ASP.NET将序列化会话状态对象,因此不允许使用不可序列化的对象或MarshalByRef对象.如果自定义会话状态存储在"自定义"模式下完成类似的序列化,则适用相同的限制.

描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

异常详细信息:System.Web.HttpException:无法序列化会话状态.在"StateServer"和"SQLServer"模式下,ASP.NET将序列化会话状态对象,因此不允许使用不可序列化的对象或MarshalByRef对象.如果自定义会话状态存储在"自定义"模式下完成类似的序列化,则适用相同的限制.

来源错误:

在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.

堆栈跟踪:

[SerializationException:在Assembly'Nop.BusinessLogic中输入'NopSolutions.NopCommerce.BusinessLogic.Categories.Category',Version = 1.9.0.0,Culture = neutral,PublicKeyToken = null'未标记为可序列化.]
System.Runtime.Serialization.FormatterServices .InternalGetSerializableMembers(RuntimeType type)+9449041
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type,StreamingContext context)+247
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()+ 160 System.Runtime.Serialization.Formatters .Binary.WriteObjectInfo.InitSerialize(类型objectType,ISurrogateSelector surrogateSelector,StreamingContext上下文,SerObjectInfoInit serObjectInfoInit,IFormatterConverter转换器,SerializationBinder binder)+371
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo,NameInfo memberNameInfo,WriteObjectInfo memberObjectInfo) +205 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo,NameInfo memberNameInfo,NameInfo typeNameInfo)+651
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph,Header [] inHeaders,__BinaryWriter serWriter,Boolean fCheck)+444 System.Runtime.Serialization.Formatters.Binary .BinaryFormatter.Serialize(流serializationStream,对象图,部首[]标头,布尔FCHECK)133 System.Web.Util.AltSerialization.WriteValueToStream(对象值,的BinaryWriter作家)1762

[HttpException(0x80004005):无法序列化会话状态.在"StateServer"和"SQLServer"模式下,ASP.NET将序列化会话状态对象,因此不允许使用不可序列化的对象或MarshalByRef对象.如果自定义会话状态存储在"自定义"模式下完成类似的序列化,则适用相同的限制.]
System.Web.Util.AltSerialization.WriteValueToStream(Object value,BinaryWriter writer)+1847
System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(对象值,BinaryWriter编写者)+34
System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer)+638
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item,Stream stream)+244
System.Web.SessionState.SessionStateUtility.SerializeStoreData (SessionStateStoreData项,Int32 initialStreamSize,Byte []&buf,Int32&length,Boolean compressionEnabled)+67
System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context,String id,SessionStateStoreData item,Object lockId,Boolean newItem)+140
System. Web.SessionState.SessionStateModule.OnReleaseState(Object source,EventArgs eventArgs)+807
System.Web.SyncEventExecutionStep.System .Web.HttpApplication.IExecutionStep.Execute()148 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔逻辑completedSynchronously)75

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272

有人请告诉我,我不需要序列化Nopcommerce中的每个对象来执行此操作!

c# asp.net serialization session-state nopcommerce

4
推荐指数
2
解决办法
1万
查看次数

正则表达式以清除html标记中的属性

我有一个非常简单的注册问题.我的HTML标记如下所示:

<body lang=EN-US link=blue vlink=purple>
Run Code Online (Sandbox Code Playgroud)

我想清除所有属性,然后返回 <body>

还有许多其他HTML标签,我想清除它们的属性,所以我希望重用该解决方案.如何使用正则表达式执行此操作?谢谢,B.

c# regex

1
推荐指数
1
解决办法
4910
查看次数

这个DELETE过程有什么问题.我们可以这样写,还是有更好的方法来编写相同的proc

这里我们只是在90天历史记录之前删除主表和子表中的记录.假设表中有超过20k的记录可供删除.在这里,我为每个5k记录提交了提交.如果我错了,请告诉我?

create or replace Procedure PURGE_CLE_ALL_STATUS  ( days_in IN number ) 
IS 

       reccount  NUMBER  := 0;

       CURSOR del_record_cur IS

    SELECT EXCEPTIONID   FROM   EXCEPTIONREC
         WHERE  trunc(TIME_STAMP) < trunc(sysdate - days_in );


BEGIN
       FOR rec IN del_record_cur LOOP

      delete from EXCEPTIONRECALTKEY   -- child table 
          where EXCEPTIONID =rec.EXCEPTIONID ;

      delete from EXCEPTIONREC -- master table
          where EXCEPTIONID =rec.EXCEPTIONID;  


         reccount := reccount + 1;

         IF (reccount >= 1000) THEN
           COMMIT;
           count := 0;
         END IF;
       commit;
       END LOOP;
       COMMIT;
       DBMS_OUTPUT.PUT_LINE('Deleted ' || total || …
Run Code Online (Sandbox Code Playgroud)

sql oracle plsql

-1
推荐指数
1
解决办法
117
查看次数