IIS URL重定向目录

时间:2016-09-22 11:19:27

标签: asp.net iis url-routing http-redirect

我在使用IIS URl重定向模块时遇到问题。 尝试从www.site.com/directory1/default.aspx重定向 到www.site.com/directory2/default.aspx

因此对directory1的任何请求都需要转到目录2.我将在目录1中禁用该应用程序 有任何想法吗? 目前我有以下,但不起作用。

<rewrite>
            <rules>
                <remove name="Portal Test Redirect" />
                <rule name="Portal Test Redirect" patternSyntax="Wildcard">
                    <match url="*directory1/*" ignoreCase="false" />
                    <conditions />
                    <serverVariables />
                    <action type="Rewrite" url="{R:1}/directory2/{R:2}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>        

2 个答案:

答案 0 :(得分:1)

您需要更改以下规则

<rewrite>
    <rules>            
        <rule name="Portal Test Redirect">
            <match url="(.*)(directory1)(.*)" patternSyntax="ECMAScript"/>
            <action type="Rewrite" url="{R:1}directory2{R:3}" />
        </rule>
    </rules>
</rewrite>

答案 1 :(得分:0)

1.在旧页面所在的目录中打开web.config 2.然后按如下所示为旧位置路径和新目标添加代码:

&#13;
&#13;
public class MainActivity extends AppCompatActivity {

    Boolean recording;


    private Button btnPlay,btnStop,btnRecord;
    private String outputFile = null;
    //outputFile = Environment.getExternalStorageDirectory().getAbsolutePath()+"/recording.3gp";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initialize();
        initViews();
        setUpViews();
    }

    private void initialize()
    {

    }

    private void initViews()
    {
        btnPlay = (Button)findViewById(R.id.btn_play);
        btnRecord = (Button)findViewById(R.id.btn_record);
        btnStop = (Button)findViewById(R.id.btn_stop);
    }

    private void setUpViews()
    {
        btnRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startRecord();
            }
        });

        btnStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                recording = false;
                Toast.makeText(getBaseContext(),"Stopped",Toast.LENGTH_SHORT).show();
            }
        });

        btnPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                playRecord();
            }
        });
    }

    private void startRecord(){

        File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");

        try {
            file.createNewFile();

            OutputStream outputStream = new FileOutputStream(file);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
            DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);

            int minBufferSize = AudioRecord.getMinBufferSize(11025,
                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT);

            short[] audioData = new short[minBufferSize];

            AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                    11025,
                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT,
                    minBufferSize);

            audioRecord.startRecording();

            Toast.makeText(getBaseContext(),"Recording",Toast.LENGTH_SHORT).show();

            while(recording){
                int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
                for(int i = 0; i < numberOfShort; i++){
                    dataOutputStream.writeShort(audioData[i]);
                }
            }

            audioRecord.stop();
            dataOutputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private void playRecord(){

        File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");

        int shortSizeInBytes = Short.SIZE/Byte.SIZE;

        int bufferSizeInBytes = (int)(file.length()/shortSizeInBytes);
        short[] audioData = new short[bufferSizeInBytes];

        try {
            InputStream inputStream = new FileInputStream(file);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
            DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);

            int i = 0;
            while(dataInputStream.available() > 0){
                audioData[i] = dataInputStream.readShort();
                i++;
            }

            dataInputStream.close();

            AudioTrack audioTrack = new AudioTrack(
                    AudioManager.STREAM_MUSIC,
                    11025,
                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT,
                    bufferSizeInBytes,
                    AudioTrack.MODE_STREAM);

            audioTrack.play();
            audioTrack.write(audioData, 0, bufferSizeInBytes);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
&#13;
&#13;
&#13;

尝试以上。参考Setting up redirect in web.config file